package com.liuzh.fitnessplan.database.dao

import androidx.room.*
import com.liuzh.fitnessplan.database.bean.TimePlans

@Dao
interface TimeDao {
    @Insert
    fun addData(plans : TimePlans)

    @Query("SELECT * FROM TimePlans WHERE userId = :id")
    fun getInitData(id : Int) : List<TimePlans>

    @Query("DELETE  FROM TimePlans WHERE id = :id")
    fun delOneData(id: Int)

    @Query("DELETE FROM TimePlans WHERE userId = :userId")
    fun delByUserId(userId : Int)

    @Query("SELECT * FROM TimePlans WHERE id = :id")
    fun getSingleData(id: Int):TimePlans

    @Update
    fun update(timePlans: TimePlans)

    @Query("UPDATE TimePlans SET isOpen = :isOpen WHERE id = :id")
    fun setOpenStatus(isOpen : Boolean , id: Int)

    @Query("SELECT id FROM TimePlans ORDER BY id DESC LIMIT 1")
    fun getId():Int

    @Query("SELECT * FROM TimePlans WHERE userId = :userId AND isOpen = 1")
    fun getOpenItem(userId: Int):List<TimePlans>
}